package com.cnyz.service.impl;

import com.cnyz.dto.CourseFileDto;
import com.cnyz.entity.CourseFile;
import com.cnyz.service.CourseFileService;
import com.cnyz.service.TranscribeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import static com.cnyz.utils.FileUtil.extractTextFromVideo;
import static com.cnyz.utils.FileUtil.urlToLocalPath;

@Service

public class TrancribeServiceImp implements TranscribeService {

    @Autowired
    CourseFileService courseFileService;

    @Override
    @Async
    public void transcribeVideoToText(Long id) {

        //找到本地路径
        String filePath = courseFileService.getCourseFileById(id).getPath();
        filePath = urlToLocalPath(filePath);//线上路径转本地路径

        String text=extractTextFromVideo(filePath);
        System.out.println("转化完成"+text);
        CourseFileDto courseFileDto= new CourseFileDto();
        courseFileDto.setText(text);
        courseFileDto.setId(id);

        courseFileService.updateCourseFileText(courseFileDto); //更新课程文件的文本内容


        //调用转文本工具类
    }//异步执行转文本函数
}
